package com.lizhi.dingdong.apk.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.lizhi.dingdong.apk.data.NotificationItem
import com.lizhi.dingdong.apk.ui.theme.Dingdong_apkTheme

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NotificationScreen(notificationList: List<NotificationItem> = emptyList()) {
    Scaffold(
        topBar = {
            Column {
                // 模仿顶部的“通知”标题栏
                TopAppBar(
                    title = {
                        Text(
                            "通知",
                            fontSize= 30.sp
                        )
                    },
                    actions = {
                        IconButton(onClick = { /* 搜索 */ }) {
                            Icon(Icons.Default.Search, contentDescription = "Search")
                        }
                        IconButton(onClick = { /* 更多选项 */ }) {
                            Icon(Icons.Default.MoreVert, contentDescription = "Menu")
                        }
                    }
                )
                // ⭐ 添加分割线
                HorizontalDivider(
                    modifier = Modifier
                        .padding(vertical = 6.dp) // 增加垂直空间
                        .fillMaxWidth(),
                    thickness = 1.dp, // 线条的厚度
                    color = Color.LightGray // 线条的颜色
                )
            }
        },
    ) { innerPadding ->
        LazyColumn(
            modifier = Modifier
                .fillMaxSize()
                .padding(innerPadding) // 确保内容避开 TopBar 和 BottomBar
        ) {
            items(notificationList.reversed()) { item ->
                NotificationListItem(item = item)
            }
        }
    }
}

@Preview(showBackground = true)
@Composable
fun NotificationScreenPreview() {

    val mockData = listOf(
        NotificationItem(0, "电信", "10/18", "标题1", "内容...", Color(0xFF2196F3).toArgb()),
        NotificationItem(1, "OPPO", "10/18", "标题2", null, Color(0xFF4CAF50).toArgb())
    )

    Dingdong_apkTheme {
        NotificationScreen(mockData)
    }
}